import axios from "axios";

const API_URL = "http://localhost:8080/app/hotel"

export const getHotel = (hotelName) => {
    return axios.get(`${API_URL}/hotelName/${hotelName}`)
}
// 获得酒店的基本信息
export const getBasicInfo = (id) => {
    return axios.get(`${API_URL}/hotel/${id}`)
}

export const getHotelDetail = (hotelId) => {
    return axios.get(`${API_URL}/hotelId/${hotelId}`)
}

export const getHotelByLocation = (requestParams) => {
    return axios.get(`${API_URL}/search`, { params: requestParams });
}

export const getSearchAll = (requestParams1) => {
    return axios.post(`${API_URL}/searchAll`, requestParams1);

}




export const getHotHotel =()=>{


    return axios.get(`${API_URL}/hot`)
}

//推荐酒店
export const getRecommendHotel = (userId) => {
    return axios.get(`${API_URL}/recommend`,{
        params: { userId }
    });
};



export const getSearchEs = (keyword) => {
    return axios.get(`${API_URL}/searchES`, {
        params: { keyword }  // keyword 是字符串
    })
}


// 首页搜索 ES 高亮 + SQL 补全字段
export const searchHotelsByKeyword = (keyword) => {
    return axios.post(`${API_URL}/searchESA`, { location: keyword })
        .then(res => {
            if (res.data.code === 200) {
                return res.data.data; // 返回合并后的酒店列表
            } else {
                console.warn("ES搜索未返回结果:", res.data.msg);
                return [];
            }
        })
        .catch(err => {
            console.error("ES搜索出错:", err);
            return [];
        });
};


